﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Devtm.Contracts.V1;
using Devtm.Contracts.Configurations;

namespace Devtm.ServiceModel.Configurations
{

    public class ConfigurationContent
    {


        private static ConfigurationContent _instance;
        private System.Configuration.Configuration _configuration;

        #region Ctor


        public ConfigurationContent() { _instance._configuration = Helpers.ConfigurationHelper.GetConfiguration(); }

        static ConfigurationContent() { _instance = new ConfigurationContent(); }

        public static ConfigurationContent Instance { get { return _instance; } }

        #endregion

        public System.Configuration.Configuration Configuration<T>(string name)
            where T : System.Configuration.ConfigurationSection
        {

            T c = _configuration.GetSection(name) as T;

            if (c == null)
            {                
                
                IConfigurationContract srv = ServiceFactory.Instance.Create<IConfigurationContract>();
                List<string> contexts = ConfigurationResolver.Configuration.GetContext().ToList();
                contexts.Add(string.Format("SectionType={0}", typeof(T).AssemblyQualifiedName));
                var response = srv.Get(contexts.ToArray());

                

            }

            return _configuration;

        }

    }

}
